package xj.graph2d.tools;

import xj.graph2d.DrawShape;
import xj.graph2d.DrawShapeConstants;
import xj.graph2d.SelfLoop;
import xj.graph2d.shapes.CurveShape;

public class CurveTool extends TwoEndsDrawTool {

  public CurveTool(CurveShape shape) {
    this(shape, DrawShapeConstants.USE_SYSTEM_DRAW_ATTR, false, null, false);
  }

  public CurveTool(CurveShape shape, int cloneDrawAttrMode) {
    this(shape, cloneDrawAttrMode, false, null, false);
  }

  public CurveTool(CurveShape shape, int cloneDrawAttrMode, String shapeKey) {
    this(shape, cloneDrawAttrMode, false, shapeKey, false);
  }

  public CurveTool(CurveShape shape, 
		   int cloneDrawAttrMode, 		   
		   String shapeKey,
		   boolean scale) {
    this(shape, cloneDrawAttrMode, false, shapeKey, scale);
  }

  public CurveTool(CurveShape shape, 
		   int cloneDrawAttrMode, 		   
		   boolean reverseEnds, 
		   String shapeKey,
		   boolean scale) {
    super(shape, cloneDrawAttrMode, reverseEnds, shapeKey);
    this.scale = scale;
  }

  @Override
  protected void adjustShape(DrawShape shape, 
			     float x1, float y1, 
			     float x2, float y2) {
    if (shape instanceof CurveShape) {
      CurveShape curve = (CurveShape) shape;
      if (scale) {
	curve.setEndsAdj(x1, y1, x2, y2, true);
      } else {
	curve.setEndsAdj(x1, y1, x2, y2);
      }
    } else if (shape != null) {
      shape.setEnds(x1, y1, x2, y2);
    }

    if (shape instanceof SelfLoop) {
      SelfLoop sloop = (SelfLoop) shape;
      sloop.adjustDirection(src0 != null ? src0.getBounds() : null, x1, y1, x2, y2);
      sloop.adjustSelfLoop();
    }

  }

  protected boolean scale = true; //false;

  protected static final String MSGKEY_3 = "Tool.message.3";

}
